﻿function startTime() {
    var today = new Date();
    $('#startTime').html("")
    $('#endTime').html("")
    weui.datePicker({
        start: today,
        end: new Date().getFullYear(),
        // onChange: function(result) { },
        onConfirm: function (result) {
            console.log(result);
            var startTime = [];
            for (var i = 0; i < result.length; i++) {
                startTime.push(result[i].value)
            }
            startTime = startTime.join("-");
            startTime1 = startTime;
            console.log(startTime);
            $('#startTime').html(startTime)
        }
    });
};

function endTime() {
    weui.datePicker({
        start: startTime1,
        end: new Date().getFullYear(),
        // onChange: function(result) {
        //
        // },
        onConfirm: function (result) {
            console.log(result);
            var endTime = [];
            for (var i = 0; i < result.length; i++) {
                endTime.push(result[i].value)
            }
            endTime = endTime.join("-");
            console.log(endTime);
            $('#endTime').html(endTime)
        }
    });
};

function closeTime() {
    $('#dialog1').css('display', 'none');
}

function okTime() {
    var startTime = $('#startTime').val();
    var endTime = $('#endTime').val();
    if (checkEndTime(startTime, endTime)) {
        console.log('结束时间小于开始时间');
    }
}

function checkEndTime(startTime, endTime) {
    var start = new Date(startTime.replace("-", "/").replace("-", "/"));
    var end = new Date(endTime.replace("-", "/").replace("-", "/"));
    if (end < start)
        return false;
    return true;
}
